﻿Imports MICROFORMA.BEL
Imports MICROFORMA.DIL
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common
Imports System.Data
Imports System.Data.OleDb

Public Class IndiceGrillaDA
    Implements DIL.IndiceGrillaDI

    Dim stringConnection As String = "DockingTelerikScanFlow.My.MySettings.Setting" 'TODO: HardCode Cadena Conexion estática en 

    Public Function Add(ByVal indiceGrillaBE As BEL.IndiceGrillaBE) As String Implements DIL.IndiceGrillaDI.Add
        Dim db As Database = DatabaseFactory.CreateDatabase(stringConnection) 'TODO: HardCode
        Dim query As String

        query = "Insert into IndiceGrilla (IdGrilla,IdIndice,Orden)" _
                                & "Values ('" & indiceGrillaBE.IdGrilla & "','" & indiceGrillaBE.Indice & "'," & "," & indiceGrillaBE.Orden _
                                 & "')"


        Try


            Dim o_dbCommand As DbCommand = db.GetSqlStringCommand(query)


            db.ExecuteNonQuery(o_dbCommand)


            Return "OK"

        Catch ex As Exception

            Return ex.Message.ToString

        End Try

    End Function

    Public Function Edit(ByVal indiceGrillaBE As BEL.IndiceGrillaBE) As String Implements DIL.IndiceGrillaDI.Edit
        Dim db As Database = DatabaseFactory.CreateDatabase(stringConnection)

        Try
            Dim query As String

            query = "Update IndiceGrilla Set IdGrilla='" & indiceGrillaBE.IdGrilla _
                                 & "',IdIndice='" & indiceGrillaBE.Indice _
                                 & "',Orden=" & indiceGrillaBE.Orden _
                                 & "' where IdGrilla=" & indiceGrillaBE.IdGrilla




            Dim o_dbCommand As DbCommand = db.GetSqlStringCommand(query)


            db.ExecuteNonQuery(o_dbCommand)


            Return "OK"

        Catch ex As Exception

            Return ex.Message.ToString

        End Try
    End Function

    Public Function List() As System.Data.DataTable Implements DIL.IndiceGrillaDI.List

        Dim db As Database = DatabaseFactory.CreateDatabase(stringConnection)

        Dim query As String = "select * from IndiceGrilla order By IdGrilla "

        Dim dbCommand As DbCommand = db.GetSqlStringCommand(query)

        Dim productsDataSet As DataSet = Nothing

        productsDataSet = db.ExecuteDataSet(dbCommand)

        Return productsDataSet.Tables(0)

    End Function

    Public Function list(ByVal idGrilla As Int16) As DataTable Implements DIL.IndiceGrillaDI.List

        Dim db As Database = DatabaseFactory.CreateDatabase(stringConnection)

        Dim query As String = "select * from IndiceGrilla where IdGrilla = " & idGrilla

        Dim dbCommand As DbCommand = db.GetSqlStringCommand(query)

        Dim productsDataSet As DataSet = Nothing

        productsDataSet = db.ExecuteDataSet(dbCommand)

        Return productsDataSet.Tables(0)
    End Function

    Public Function Delete(ByVal idGrilla As Int16) As String Implements DIL.IndiceGrillaDI.Delete
        Dim db As Database = DatabaseFactory.CreateDatabase(stringConnection)

        Try
            Dim query As String = "Delete from IndiceGrilla where IdGrilla= '" & idGrilla & "'"

            Dim o_dbCommand As DbCommand = db.GetSqlStringCommand(query)

            db.ExecuteNonQuery(o_dbCommand)

            Return "OK"

        Catch ex As Exception

            Return ex.Message.ToString

        End Try
    End Function

End Class
